import { useEffect, useState } from "react";
import { useLocation, Navigate } from "react-router-dom"
const GlobalUser = ({ children }) => {
    const [count, setCount] = useState(0)
    console.log(children, "全局路由守卫Globaluser");
    const location = useLocation()
    console.log(location, "访问地址信息");
    useEffect(() => {
        setTimeout(() => {
            console.log("模拟请求,携带者token,校验有效性")
            const auth = true; // 假设这里是校验 token 的结果
            const isSendRequest = true; // 假设这里是判断是否已发送请求的标志
            if (auth && isSendRequest) {
                setCount(count + 1);
            }
        }, 1000);
    }, [location.pathname, count]);
    //全局路由守卫
    //1-是否要进入login或者xx路由
    //如果进入这两个路由-- 放行
    //2-如果进入的非login或者xxx
    //判断有没有登录
    //登录:放行
    //没登录:重定向到登录页面

    if (location.pathname.includes("/login")) { return children }
    else {
        if (true) {
            return children
        }
        else {
          if(true){
            return children
          }
          else{
            return <Navigate to="/login"></Navigate>
          }
        }
    }

}
export default GlobalUser